<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [<!ENTITY nbsp "&#160;">]>

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions">

<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:output method="text" name="textFormat"/>

<xsl:param name="outPath">src</xsl:param>

<xsl:template match="/idl">
<xsl:for-each select="bean">
<xsl:variable name="beanName"><xsl:value-of select="$outPath"/>/<xsl:value-of select="translate(@package, '.', '/')"/>/<xsl:value-of select="@name"/></xsl:variable>
<xsl:result-document href="{$beanName}Interface.java" format="textFormat">
<xsl:call-template name="iface"/> 
</xsl:result-document>
<xsl:result-document href="{$beanName}Proxy.java" format="textFormat">
<xsl:call-template name="proxy"/> 
</xsl:result-document>
<xsl:result-document href="{$beanName}.java.stub" format="textFormat">
<xsl:call-template name="stub"/> 
</xsl:result-document>

</xsl:for-each>
</xsl:template>


<xsl:template name="stub">
<xsl:text>
// this is a generated Remote Object Stub
// PLEASE EDIT !!

</xsl:text>
package <xsl:value-of select="@package"/>;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;                     

public class <xsl:value-of select="@name"/>
	implements <xsl:value-of select="@name"/>Interface {

	private Log log = LogFactory.getLog(<xsl:value-of select="@name"/>.class);

<xsl:for-each select="method">
	public <xsl:if test="@static">static </xsl:if><xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>(<xsl:for-each select="arg">
<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>
  <xsl:if test="position() != last()">
     <xsl:text>, </xsl:text>
  </xsl:if>
 </xsl:for-each>)  {
		// nonsense method stub ..
		<xsl:if test="not(@static)">
		log.info("Invoking Method:\t" + "<xsl:value-of select="@name"/>");
		</xsl:if>	
		<xsl:if test="not(@oneway)">
		<xsl:value-of select="@type"/> retval = null;
		return retval;
		</xsl:if>	

	}
</xsl:for-each>

}
</xsl:template>


<xsl:template name="iface">
<xsl:text>
// generated client interface
// DO NOT EDIT !

</xsl:text>
package <xsl:value-of select="@package"/>;

public interface <xsl:value-of select="@name"/>Interface extends java.io.Serializable {

<xsl:for-each select="method">

<xsl:if test="not(@static)">
	public <xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>(<xsl:for-each select="arg">
<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>
  <xsl:if test="position() != last()">
     <xsl:text>, </xsl:text>
  </xsl:if>
 </xsl:for-each>) throws evs.brp.RemotingErrorException ;
</xsl:if>

</xsl:for-each>

}	
</xsl:template>




<xsl:template name="proxy">
<xsl:text>
// generated client proxy
// DO NOT EDIT !
</xsl:text>
package <xsl:value-of select="@package"/>;

import evs.iap.Requestor;

import java.util.Vector;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;                     

public class <xsl:value-of select="@name"/>Proxy
	extends Requestor
	implements <xsl:value-of select="@name"/>Interface {

	private Log log = LogFactory.getLog(<xsl:value-of select="@name"/>Proxy.class);

<xsl:for-each select="method">
	public <xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>(<xsl:for-each select="arg">
<xsl:value-of select="@type"/><xsl:text> </xsl:text><xsl:value-of select="@name"/>
  <xsl:if test="position() != last()">
     <xsl:text>, </xsl:text>
  </xsl:if>
 </xsl:for-each>) throws evs.brp.RemotingErrorException {
	<xsl:if test="not(@static)">
		log.info("Invoking Method:\t" + "<xsl:value-of select="@name"/>");
	</xsl:if>	
	<xsl:text>
		Vector &lt;Class &gt;  argumentClazzes = new Vector&lt;Class&gt;();
	</xsl:text>
	<xsl:for-each select="arg">
		argumentClazzes.add(<xsl:value-of select="@type"/>.class);
	</xsl:for-each>
		Vector&lt;String&gt; argumentNames = new Vector&lt;String&gt;();
	<xsl:for-each select="arg">
		argumentNames.add("<xsl:value-of select="@name"/>");
	</xsl:for-each>
		Vector&lt;Object&gt; arguments = new Vector&lt;Object&gt;();
	<xsl:for-each select="arg">
		arguments.add(<xsl:value-of select="@name"/>);
	</xsl:for-each>
		Object object = null;


		log.debug("Invoking Method:\t" + "<xsl:value-of select="@name"/>");

	<xsl:if test="@oneway">
		object = this.syncWithServerInvoke("<xsl:value-of select="../@remoteClass"/>", "<xsl:value-of select="@name"/>", 
				argumentClazzes, argumentNames, arguments, 
				<xsl:value-of select="@type"/>.class);
	</xsl:if>
	
	<xsl:if test="not(@oneway)">
		object = this.invoke("<xsl:value-of select="../@remoteClass"/>", "<xsl:value-of select="@name"/>", 
				argumentClazzes, argumentNames, arguments, 
				<xsl:value-of select="@type"/>.class);
	</xsl:if>
		
	<xsl:if test="not(@type='void')">
		return (<xsl:value-of select="@type"/>)object;
	</xsl:if>
	}
</xsl:for-each>


}
</xsl:template>





</xsl:stylesheet>
